from rest_framework import serializers
from apps.accounts.serializers import UserSimpleSerializer
from .models import Dish, DishCategory

class DishCategorySerializer(serializers.ModelSerializer):
    class Meta:
        model = DishCategory
        fields = ['id', 'name', 'image', 'description']

class DishSerializer(serializers.ModelSerializer):
    category = DishCategorySerializer(read_only=True)
    chef = serializers.SerializerMethodField()

    class Meta:
        model = Dish
        fields = '__all__'
        read_only_fields = ['chef', 'created_at']

    def get_chef(self, obj):
        from apps.accounts.serializers import UserSimpleSerializer
        return UserSimpleSerializer(obj.chef.user).data

class DishCreateUpdateSerializer(serializers.ModelSerializer):
    class Meta:
        model = Dish
        fields = [
            'name', 'description', 'price', 'image', 
            'category', 'is_spicy', 'prep_time', 'is_available'
        ]
        extra_kwargs = {
            'image': {'required': True},
            'category': {'required': True}
        }